package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceWork;
import com.ruoyi.service.service.IServiceWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全作业Controller
 * 
 * @author yepanpan
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/service/work")
public class ServiceWorkController extends BaseController
{
    @Autowired
    private IServiceWorkService serviceWorkService;

    /**
     * 查询安全作业列表
     */
    @PreAuthorize("@ss.hasPermi('service:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceWork serviceWork)
    {
        startPage();
        List<ServiceWork> list = serviceWorkService.selectServiceWorkList(serviceWork);
        return getDataTable(list);
    }

    /**
     * 导出安全作业列表
     */
    @PreAuthorize("@ss.hasPermi('service:work:export')")
    @Log(title = "安全作业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceWork serviceWork)
    {
        List<ServiceWork> list = serviceWorkService.selectServiceWorkList(serviceWork);
        ExcelUtil<ServiceWork> util = new ExcelUtil<ServiceWork>(ServiceWork.class);
        util.exportExcel(response, list, "安全作业数据");
    }


    /**
     * 获取安全作业详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceWorkService.selectServiceWorkById(id));
    }

    /**
     * 新增安全作业
     */
    @PreAuthorize("@ss.hasPermi('service:work:add')")
    @Log(title = "安全作业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceWork serviceWork)
    {
                serviceWork.setCreateBy(getUsername());
        return toAjax(serviceWorkService.insertServiceWork(serviceWork));
    }

    /**
     * 修改安全作业
     */
    @PreAuthorize("@ss.hasPermi('service:work:edit')")
    @Log(title = "安全作业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceWork serviceWork)
    {
                serviceWork.setUpdateBy(getUsername());
        return toAjax(serviceWorkService.updateServiceWork(serviceWork));
    }

    /**
     * 删除安全作业
     */
    @PreAuthorize("@ss.hasPermi('service:work:remove')")
    @Log(title = "安全作业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceWorkService.deleteServiceWorkByIds(ids));
    }
}
